package com.manage.platform.controller;

import com.manage.platform.dto.PositionDto;
import com.manage.platform.dto.query.PositionPageQuery;
import com.manage.platform.service.impl.PositionServiceImpl;
import com.manage.platform.utils.R;
import com.manage.platform.utils.RPage;
import com.manage.platform.vo.CommonVo;
import com.manage.platform.vo.PositionVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * YWD
 * 2025/9/24
 */
@AllArgsConstructor
@RestController
@RequestMapping("/position")
@Tag(name = "学校基础信息-岗位管理")
public class PositionController {

  private final PositionServiceImpl positionService;

    @PostMapping("/getPositionPage")
    @Operation(summary = "查询岗位列表(分页)")
    public R<RPage<List<PositionVo>>> getPositionPage(@RequestBody PositionPageQuery query){
        return R.ok(positionService.getPositionPage(query));
    }

    @GetMapping("/getPositionDetails/{id}")
    @Operation(summary = "查询岗位详情")
    public R<PositionVo> getPositionDetails(@Schema(description = "岗位ID") @PathVariable("id") Long id){
        return R.ok(positionService.getPositionDetails(id));
    }

    @PostMapping("/savePosition")
    @Operation(summary = "添加岗位")
    public R<Boolean> savePosition(@RequestBody PositionDto dto){
        return R.ok(positionService.savePosition(dto));
    }

    @PutMapping("/updatePosition")
    @Operation(summary = "修改岗位")
    public R<Boolean> updatePosition(@RequestBody PositionDto dto){
        return R.ok(positionService.updatePosition(dto));
    }

    @DeleteMapping("/deletePosition/{id}")
    @Operation(summary = "删除岗位")
    public R<Boolean> deletePosition(@Schema(description = "岗位ID") @PathVariable("id") Long id){
        return R.ok(positionService.deletePosition(id));
    }

    @GetMapping("/getPositionList")
    @Operation(summary = "职称列表(筛选项)")
    public R<List<CommonVo>> getPositionList(@Schema(description = "职称名称") @RequestParam(value = "name", required = false) String name) {
        return R.ok(positionService.getPositionList(name));
    }

}
